package com.example.yuejianapp14.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejianapp14.Activity.Activity.RegActivity;
import com.example.yuejianapp14.Activity.Activity.Video1Activity;
import com.example.yuejianapp14.Activity.Activity.ViewVideoActivity;
import com.example.yuejianapp14.Activity.JavaBean.Video1;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 张森 on 2017/11/6.
 */

public class VideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Video1> mDataList;
    private LayoutInflater mLayoutInflater;

    public VideoAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.zsvideocard,parent,false);
        return new VideoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final Video1 entity = (Video1) mDataList.get(position);
//        if (null == entity)
//            return;

        VideoAdapter.ViewHolder viewHolder = (VideoAdapter.ViewHolder) holder;
        viewHolder.video_name.setText(entity.getName());

        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/thumbnail/"+entity.getThumbnail()).into(viewHolder.video_pic);
        // viewHolder.news_stars.setRating(Float.parseFloat(entity.get("news_stars").toString()));
        // viewHolder.news_thumb.setIIntegemageResource(r.parseInt(entity.get("news_thumb").toString()));
        viewHolder.zsvideopic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, ViewVideoActivity.class);
                intent.putExtra("videopath",mDataList.get(position).getVideopath());
                mContext.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView video_pic;
        TextView video_name;
        ImageView zsvideopic;

        public ViewHolder(View itemView) {
            super(itemView);
            video_name = (TextView) itemView.findViewById(R.id.zsvideoname);
            video_pic = (ImageView) itemView.findViewById(R.id.zsvideopic);
            zsvideopic=(ImageView) itemView.findViewById(R.id.zsvideopic);
        }
    }
}
